
function PP.GetClass( ply )

	local class = ply:GetNWString( "class" )
	local ret = "NILL"
	
	for k,v in pairs( PP.Class ) do
	
		if v.Arg == class then ret = v.Name end
		
	end
	
	return ret
	
end

function PP.GetClassSize( class )

	local players = player.GetAll()
	local data = 0
	
	for k,v in pairs(players) do
	
		if !v:IsPlayer() then return end
		
		local plyclass = v:GetNWString( "class" )
		
		if plyclass == class then data = data + 1 end
		
	end
	
	return data
	
end

function PP.CheckClassSize( class )

	for k,v in pairs( PP.Class ) do
	
		if v.Arg == class then
		
			if v.Max == 0 then return false end
			if v.Max <= PP.GetClassSize( class ) then
			
				return true
				
			end
			
		end
		
	end
	
end

function PP.AlreadyInClass( ply, class )

	local plyclass = ply:GetNWString( "class" )
	
	for k,v in pairs( PP.Class ) do
	
		if v.Arg == class and plyclass == v.Arg then 
			return true
		end
		
	end
	
end

function PP.JoinClass( ply, _, arg )

	local arg = arg[1]
	
	for k,v in pairs( PP.Class ) do
	
		if v.Arg == arg then
		
			if PP.CheckClassSize( arg ) then
				Print( "You can't join that class, its full!" )	
				break
			end
			
			if PP.AlreadyInClass( ply, arg ) then	
				Print( "You already are that class!" )
				break
			end
			
			ply:SetTeam( v.Team )
			ply:SetNWString( "class", arg )
			ply:KillSilent()
			ply:Spawn()
			
			Print( "Player " .. ply:Nick() .. " has joined class " .. v.Name )
			
		end
		
	end
	
end
concommand.Add( "joinclass", PP.JoinClass )
	
function PP.AddClass( name, arg, max, t, spawn )

	local class = {}
	
	class.Name = name
	class.Arg = arg
	class.Max = max
	class.Team = t
	class.Spawn = spawn
	
	table.insert( PP.Class, class )
	
end

	PP.AddClass( "Col. Smithfield", "smithfield", 1, 1, "info_atlantis_start" )
	
	PP.AddClass( "Bob the Wraith", "bobtw", 1, 2, "info_wraith_start" )